#include "Point.h"

SPoint SPoint::UNKNOWN = SPoint(999999., 999999., 999999.);

SPoint::SPoint(void) :
	x(UNKNOWN.x), y(UNKNOWN.y), z(UNKNOWN.z)
{
}

SPoint::SPoint(const float _x, const float _y, const float _z) :
	x(_x), y(_y), z(_z)
{
	//ctor
}

SPoint::SPoint(const SPoint& copy) :
	x(copy.x), y(copy.y), z(copy.z)
{
}

SPoint::~SPoint()
{
	//dtor
}

void SPoint::rotateAround(const Vector& v, float a)
{
	float ux = x * v.x;
	float uy = y * v.x;
	float uz = z * v.x;
	float vx = x * v.y;
	float vy = y * v.y;
	float vz = z * v.y;
	float wx = x * v.z;
	float wy = y * v.z;
	float wz = z * v.z;
	float sa = sin(a);
	float ca = cos(a);
	x = v.x*(ux+vy+wz)+(x*(v.y*v.y+v.z*v.z)-v.x*(vy+wz))*ca+(-wy+vz)*sa;
	y =v.y*(ux+vy+wz)+(y*(v.x*v.x+v.z*v.z)-v.y*(ux+wz))*ca+(wx-uz)*sa;
	z = v.z*(ux+vy+wz)+(z*(v.x*v.x+v.y*v.y)-v.z*(ux+vy))*ca+(-vx+uy)*sa;

//	Rotate the point (x,y,z) around the vector (u,v,w)
//	Function RotatePointAroundVector(x#,y#,z#,u#,v#,w#,a#)
//	ux#=u*x
//	uy#=u*y
//	uz#=u*z
//	vx#=v*x
//	vy#=v*y
//	vz#=v*z
//	wx#=w*x
//	wy#=w*y
//	wz#=w*z
//	sa#=Sin(a)
//	ca#=Cos(a)
//	x#=u*(ux+vy+wz)+(x*(v*v+w*w)-u*(vy+wz))*ca+(-wy+vz)*sa
//	y#=v*(ux+vy+wz)+(y*(u*u+w*w)-v*(ux+wz))*ca+(wx-uz)*sa
//	z#=w*(ux+vy+wz)+(z*(u*u+v*v)-w*(ux+vy))*ca+(-vx+uy)*sa
//	End Function
	
	
}

std::ostream& operator<<(std::ostream& ostr, const SPoint& v)
{ 
  return ostr << "x: " << v.x << " y: " << v.y << " z: " << v.z; 
} 
